/**
 * Copyright 2012 Pablo Danilo Aliscioni
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 */

package ar.com.pabloaliscioni.cloud.core.configuration;

import java.io.Serializable;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

/**
 * Represents a configuration parameter deserialized form the XML configuration file for a given provider
 * 
 * @author Pablo Danilo Aliscioni
 * @since 1.0
 */
@XStreamAlias("item")
public class ProviderConfigurationElement implements Serializable
{
	/**
	 * Generated Serial Version UID
	 */
	private static final long serialVersionUID = 2145806171989165489L;
	
	/**
	 * Key of the parameter
	 */
	@XStreamAlias("key")
   	@XStreamAsAttribute
	private String key;
	
	/**
	 * Value of the parameter
	 */
	@XStreamAlias("value")
   	@XStreamAsAttribute
	private String value;
	
	/**
	 * Non-parameterized constructor
	 */
	public ProviderConfigurationElement()
	{
		super();
	}
	
	/**
	 * Parameterized constructor
	 * 
	 * @param key Key of the parameter
	 * @param value Value of the parameter
	 * 
	 * @throws IllegalArgumentException If the configuration key is invalid
	 */
	public ProviderConfigurationElement(String key, String value)
	{
		super();
		
		this.setKey(key);
		this.setValue(value);
	}
	
	/**
	 * Gets the key of the parameter
	 * 
	 * @return The key of the parameter
	 */
	public String getKey()
	{
		return key;
	}
	/**
	 * Sets the key of the parameter
	 * 
	 * @param key The key of the parameter
	 * 
	 * @throws IllegalArgumentException If the configuration key is invalid
	 */
	public void setKey(String key)
	{
		if(key == null || key.isEmpty())
			throw new IllegalArgumentException("The provided configuration key is invalid");
		
		this.key = key;
	}
	
	/**
	 * Gets the value of the parameter
	 * 
	 * @return The value of the parameter
	 */
	public String getValue()
	{
		return value;
	}
	/**
	 * Sets the value of the parameter
	 * 
	 * @param value The value of the parameter
	 * 
	 * @throws IllegalArgumentException If the configuration value is invalid
	 */
	public void setValue(String value)
	{
		if(value == null)
			throw new IllegalArgumentException("The provided configuration key is invalid");
		
		this.value = value;
	}
}
